﻿using System;
using System.Collections;
using System.Web.Caching;

namespace NWebMock
{
    public class CacheWrapper : ICache
    {
        #region Constructors

        public CacheWrapper(Cache cache)
        {
            if (cache == null)
            {
                throw new ArgumentNullException("cache");
            }

            this.innerCache = cache;
        }

        #endregion

        #region Fields

        private Cache innerCache = null;

        #endregion

        #region Properties

        public int Count { get { return this.innerCache.Count; } }

        public long EffectivePercentagePhysicalMemoryLimit { get { return this.innerCache.EffectivePercentagePhysicalMemoryLimit; } }

        public long EffectivePrivateBytesLimit { get { return this.innerCache.EffectivePrivateBytesLimit; } }

        public object this[string key] { get { return this.innerCache[key]; } set { this.innerCache[key] = value; } }

        #endregion

        #region Methods

        public object Add(string key, object value, CacheDependency dependencies, DateTime absoluteExpiration, TimeSpan slidingExpiration, CacheItemPriority priority, CacheItemRemovedCallback onRemoveCallback)
        {
            return this.innerCache.Add(key, value, dependencies, absoluteExpiration, slidingExpiration, priority, onRemoveCallback);
        }

        public object Get(string key)
        {
            return this.innerCache.Get(key);
        }

        public IDictionaryEnumerator GetEnumerator()
        {
            return this.innerCache.GetEnumerator();
        }

        public void Insert(string key, object value)
        {
            this.innerCache.Insert(key, value);
        }

        public void Insert(string key, object value, CacheDependency dependencies)
        {
            this.innerCache.Insert(key, value, dependencies);
        }

        public void Insert(string key, object value, CacheDependency dependencies, DateTime absoluteExpiration, TimeSpan slidingExpiration)
        {
            this.innerCache.Insert(key, value, dependencies, absoluteExpiration, slidingExpiration);
        }

        public void Insert(string key, object value, CacheDependency dependencies, DateTime absoluteExpiration, TimeSpan slidingExpiration, CacheItemUpdateCallback onUpdateCallback)
        {
            this.innerCache.Insert(key, value, dependencies, absoluteExpiration, slidingExpiration, onUpdateCallback);
        }

        public void Insert(string key, object value, CacheDependency dependencies, DateTime absoluteExpiration, TimeSpan slidingExpiration, CacheItemPriority priority, CacheItemRemovedCallback onRemoveCallback)
        {
            this.innerCache.Insert(key, value, dependencies, absoluteExpiration, slidingExpiration, priority, onRemoveCallback);
        }

        public object Remove(string key)
        {
            return this.innerCache.Remove(key);
        }

        #endregion

        #region IEnumerable Members

        IEnumerator IEnumerable.GetEnumerator()
        {
            return ((IEnumerable)this.innerCache).GetEnumerator();
        }

        #endregion
    }
}
